home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok44.lha
/
Crypt
/
crypt.mod
< prev
next >
Wrap
Text File
|
1993-08-15
|
3KB
|
118 lines
(**********************************************************************
:Program. Crypt
:Contents. Verschlüsselt Dateien
:Author. Steffen Reith
:Address. Hessenstr. 64, D-8700 Würzburg
:Language. Modula-2
:Translator. M2Amiga A+L V3.2d
**********************************************************************)
MODULE Crypt;
FROM Arguments IMPORT NumArgs,GetArg;
FROM Dos IMPORT Read,Write,Open,Close,FileHandlePtr,newFile,oldFile,
Seek,beginning;
FROM Terminal IMPORT WriteString,WriteLn;
FROM SYSTEM IMPORT ADR,ADDRESS,BITSET,CAST;
FROM Arts IMPORT Terminate,TermProcedure;
FROM RandomNumber IMPORT PutSeed,RND;
FROM Exec IMPORT Byte;
FROM Str IMPORT Compare;
CONST Kennung='Amiga CRYPT V1.0';
Max=1FFFH;
TYPE String=ARRAY[0..01FFH] OF CHAR;
Bu=ARRAY[0..Max] OF Byte;
VAR ArgLen,NArg,rn:INTEGER;
Buffer:Bu;
Length,Summe,Pos,i:LONGINT;
PrgName,a1,a2,a3,KennBuff:String;
In,Out:FileHandlePtr;
Flag:BOOLEAN;
PROCEDURE Eor(a,b:INTEGER):Byte;
VAR S1,S2,not,nota,notb,erg:BITSET;
BEGIN
S1:=CAST(BITSET,a);
S2:=CAST(BITSET,b);
not:=CAST(BITSET,-1);
nota:=not-S1;
notb:=not-S2;
erg:=(nota*S2)+(notb*S1);
RETURN Byte(CAST(INTEGER,erg))
END Eor;
PROCEDURE CleanUp();
BEGIN
IF In#NIL THEN Close(In) END;
IF Out#NIL THEN Close(Out) END;
END CleanUp;
BEGIN
TermProcedure(CleanUp);
GetArg(0,PrgName,ArgLen);
NArg:=NumArgs();
IF NArg=1 THEN
GetArg(1,a1,ArgLen);
IF (a1[0]='-') AND (a1[1]='h') THEN
WriteString('Usage : ');
WriteString(PrgName);
WriteString(' key File1 File2 ');WriteLn
ELSE
WriteString('Unknown Option! ');WriteLn;
WriteString('Type ');
WriteString(PrgName);
WriteString(' -h for help ');
WriteLn
END;
ELSIF (NArg=3) THEN
GetArg(2,a2,ArgLen);
GetArg(3,a3,ArgLen);
In:=Open(ADR(a2),oldFile);
IF In=NIL THEN
WriteString('Can not find ');
WriteString(a2);WriteLn;
Terminate(0)
END;
Out:=Open(ADR(a3),newFile);
IF Out=NIL THEN
WriteString('Can not open ');
WriteString(a3);WriteString(' as outputfile!');WriteLn;
Terminate(0)
END;
GetArg(1,a1,ArgLen);
Summe:=0;
FOR i:=0 TO ArgLen DO
Summe:=(Summe+LONGINT(a1[i])) MOD 07735A000H;(* Es gibt ca. 2E9 Schluessel *)
END;
PutSeed(Summe);
Length:=Read(In,ADR(KennBuff),SIZE(Kennung));
IF ABS(Compare(KennBuff,Kennung))#0 THEN
(* Uncodiertes File *)
Pos:=Seek(In,0,beginning); (* Zeiger richtig positionieren *)
Length:=Write(Out,ADR(Kennung),SIZE(Kennung))
END;
LOOP
Length:=Read(In,ADR(Buffer),SIZE(Buffer));
IF Length=0 THEN EXIT END;
FOR i:=0 TO Length-1 DO
rn:=RND(0100H)-080H;
Buffer[i]:=Eor(INTEGER(Buffer[i]),rn)
END;
Length:=Write(Out,ADR(Buffer),Length)
END
ELSE
WriteString('Illegal number of Arguments !');WriteLn;
WriteString('Type ');
WriteString(PrgName);
WriteString(' -h for help ');
WriteLn
END
END Crypt.